<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>v-on说明</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="./vue.js"></script>
</head>
<style>
    #app {
        width: 100%;
    }

    .num {
        width: 100%;
        /* color:linear-gradient(#e66465, #9198e5); */
        color: red;
        font-size: 50px;
        /* margin: 0 auto; */
        display: block;


    }

    .btn-group {
        width: 100%;
        /* padding: 30px; */
    }
</style>

<body>
    <div id="app">
        <h3 class="num">{{counter}}</h3>
        <h3 class="num">{{message}}</h3>
        <div class="btn-group">
            <button @click="add">add</button>
            <button @click="subtract">subtract</button>
            <button @click="reset">reset</button>
        </div>

    </div>
    <script>
        const obj = {
            counter: 0,
            message: 'abc'
        };
        const app = new Vue({
            el: '#app',
            data: obj,
            methods: {
                add: function () {
                    console.log("add被执行")
                    this.counter++;
                },
                subtract: function () {
                    this.counter--;
                },
                reset: function () {
                    console.log("reset被执行")
                    this.counter = 0;
                }
            },
        });
    </script>


</body>

</html>